Skip to content

feat(core): new native core behind Rees46Config.coreV2 (DEV-4724) - #238

Merged
Xyzcancer merged 109 commits into
masterfrom
feat/DEV-4724-core
Nov 16, 2026
Merged

Xyzcancer merged 109 commits into
masterfrom
feat/DEV-4724-core

Conversation

@Xyzcancer

@Xyzcancer Xyzcancer commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

New native core (DEV-4724), behind Rees46Config.coreV2, false by default. With the flag off the SDK keeps the 2.49.0 behaviour; the new public members exist in both modes, so this is a minor release.

With coreV2 = true:

  • init state machine with retries and onStateChange, a refused shop is remembered;
  • the session is the server's seance, 2 h window checked on every request;
  • a persistent queue per shop with a push lane and a tracking lane: retries, Retry-After, TTL 7 d, cap 1000;
  • push events (delivered/opened/clicked/closed) go through the queue, no track/received; the token goes at most once a week per shop;
  • SdkError / SdkResult / CompletionListener, flush(), the log codes table;
  • an API for the Flutter and React Native bridges behind @BridgeApi.

On both cores:

  • deleteUserCredentials() no longer hangs when cancelled midway, Rees46Config.deviceId is taken once per shop;
  • after needReInitialization the push token goes to the new did instead of waiting out the week;
  • the deprecated initialize() for another shop no longer leaves the object registered under the old one;
  • a cold start by a push for a shop without a did sends only /init and track/received, as 2.49.0.

minSdk 19 → 23, OkHttp 4.12.

…nor stuck when /init releases them: the did check, the queueing and the release share one lock, so the release no longer races new requests into a ConcurrentModificationException
…Config.logLevel (warning by default) and Rees46.setLogHandler with SdkLogMessage (level, stable code, message, shop, context); requests are logged by method and path, and answer bodies, push payloads and the stories answer stay out of the log on every level
…s, fakes for connectivity and the app's lifecycle, and the shared contract fixtures (contract 0: init, tracking) loaded and checked for shape
…ws that still have them are listed in a baseline that may only shrink, and the registry, purchase tracking, search params and popups v3 handle the null instead
… an exception is written to logcat and the log handler as its class name only, popups and stories log no links or image URLs, and a failed popups v3 list is logged by its HTTP code, not the answer's message
…e methods, stories, popups, stories v3 and the push token log under their shop; PopupsV3.debug writes the engine's lines whatever the level; release() keeps the shop's level while another of its instances is live; the network and init helpers check the level before reading the shop
…not when CoreDispatchers.DEFAULT is made; handleInitError loses its unused message parameter; the stories polls take the log path from StoriesApiV3.pathOf instead of a copy
…acters, and the baseline must stay exact: a file with fewer `!!` than allowed, a listed file that is gone and an unlisted file with `!!` all fail and say which line to change
…t is init_failed (error), init gives up with a warning, an answered /init is init_succeeded, needReInitialization is device_id_reset; request_failed is an error on 4xx and a warning otherwise, the stories v3 client logs request and request_failed; the advertising id has its own codes; push token, decoding and popup_not_shown lines are warnings; a notification-only FCM message and a clicked push without type or code are push_dropped
…hat wait for a did are released after /init stored the server's did, not before /init was sent, when they went out with an empty did
…ion 0003 sets: current Firebase Messaging and media3 need it, and apps below it stay on the last release
…its tests; its kotlin-stdlib 2.2 takes the SDK to Kotlin 2.1.21 and Dagger 2.57.2, whose processor reads that metadata, so apps need a Kotlin compiler of 2.1 or later; 5.4 and later are left out because they make apps compile against Android 36 or 37
…tivity, app lifecycle) and their fakes move to com.personalization.core.internal, leaving com.personalization.core to the public types
…, shopBlocked, invalidArgument, network, timeout, http with the server's code, decoding, cancelled) with a log message each, SdkException for suspending calls, and one mapping to the old onError(code, msg): the HTTP code, 402 for a blocked shop, -1 without an answer
…: the first initialize or registerShops decides, a later instance asking for the other one logs core_flag_mismatch) and a Core per instance that the request funnel hands every request to; LegacyCore is today's path, CoreV2 sends through a new OkHttp client with a pool shared by the process: common fields in one place, 5 s to connect, 10 s to read and 5 s for /init, any 2xx a success and an empty one an empty object, a body that does not parse a decoding error, no answer network before the request reached the server and timeout after, a request without a network fails at once, release() cancels the instance's requests and fails later ones, no retries, method, path and code in the log; answers still reach the old callbacks as JSON, errors through the SdkError mapping
… of 2xx, empty, unparsable and non-2xx answers, a body cut midway, the read timeouts of requests and /init, a refused connection, no network, no retries, the common fields of GET and POST, a log without data, cancel on release, the funnel switching cores, the did-gated queue on the new core and an instance made with coreV2
…he popups v3 link and product handlers, the stories viewer's shareUrlTransform), and needReInitialization logs no device_id_reset: the legacy path asks /init again but keeps the did
…r: -1 for a failure without an answer where no connection used to be 504, and a 2xx whose body is not JSON fails instead of succeeding empty
…in a snapshot replaced under a lock instead of ConcurrentHashMap.compute, which needs Android 7; the connectivity monitor walks its listeners with a plain loop
…b 2.2 metadata that OkHttp 5 brings and reported every Kotlin forEach as the Java 8 one; the Compose runtime's CoroutineCreationDuringComposition check, which crashes on that metadata, is off
…needs nothing new to build: its kotlin-stdlib is older than the 2.0.0 the SDK already brings and it adds no androidx.startup initializer; the SDK is back on Kotlin 2.0.0, Dagger 2.51.1 with its 2.48 compiler and the lint of AGP 8.5 with every check on, and the core's tests run on okhttp3's mockwebserver
… SDK's (a notification-only FCM message, a clicked notification without type or code) is push_dropped at debug with reason not_sdk_push, one no shop takes a warning with unknown_shop or ambiguous_shop; the steps before a push reaches its shop log under push and push_received only once a shop takes it; a token from FCM or HMS is push_token_received; a request release() cancels is request_cancelled; the offline fast-fail is request_failed with reason offline; a popup the app kept back or that automatic presentation left out is popup_not_shown at debug with app_declined or auto_presentation_off; a Google Play pre-launch device skips /init with init_skipped
…zation_sdk.device) takes the A/B group of the first shop that has one, the push tokens and the advertising id, while each shop's keys keep being written so the legacy path reads what it read; a shop without a group gets the device's; each shop's partition holds one-shot migration flags, the refused state, the last /init answer (read and write, in noBackupFilesDir) and its queue's directory; Rees46Config.storageKey prefixes the partition (<storageKey>_personalization_sdk_<shopId>), and the file named exactly that key, the whole store of SDK.initialize(preferencesKey) in earlier releases, is read into it once and kept; the file all shops shared before partitions goes into each shop at most once; a did is committed before the write returns, and disk failures are storage_failed with context.op
…rm with a CompletionListener called once on the main thread, forgets the shop's customer on both cores: did, sid and the last activity, the saved /init answer, the tracking source and the push token's send dates, so the token goes to the next customer, and on the new core the queue's directory; the stories' state, the device's push token, A/B group and advertising id stay; it logs device_id_reset, keeps the instance registered and asks /init again without a did, ignoring the answer to an /init sent before and fetching the push token only once the new did is stored; an instance never initialized gets notInitialized
… shared file with and without a shop, a partition of a later release, a custom preferencesKey file, a storageKey of its own, a key that cannot name a file) and a second start that repeats nothing; the device level (the first shop's A/B group, the tokens and advertising id offered once, a later token written for both); the saved /init answer, the refused state and the queue's directory; what deleteUserCredentials wipes and keeps on each core, the token going to the next customer, the /init after it through the SDK, a stale answer dropped, the listener form and an instance never initialized; Rees46Config.storageKey from Java
…so under Turkish or Azerbaijani the flavor keeps an ASCII I instead of İ, which OkHttp refuses in a header and which failed every request of the new core
…fore the wipe and an /init answer writes the did only under the lock that begins it, so an answer landing during the wipe can no longer bring the forgotten did back, and each restart has a start of its own; the did, the sid and seance also go from the stores a migration reads (the store of releases before partitions when it is the shop's, the old preferencesKey file), so a restore that lost the partition cannot read them back, and the shop's recent searches and the widgets' cached answers go too; a wipe that does not reach the disk logs storage_failed at error instead of device_id_reset and still ends normally; the Java form takes a CompletionListener<Unit> that gets an SdkResult, as the contract has them; the old preferencesKey file gives the partition the SDK's own keys only; the dead legacy-file branch of the preferences data source and the second copy of the file-name pattern are gone, and the docs list every file of the SDK for an app's backup rules and say that a new storageKey on an existing install starts every customer anew
…e requests that wait for one until the did is stored, on a new install before /init answers and after deleteUserCredentials(), whether the app set it, a provider delivered it or onNewToken brought it, on both cores; the app's OnPushTokenListener still hears of it at once
… class only, never its text or a stack trace (a popups v3 element that failed to render, a popup image, a popup link no app opened, a notification image); the lines of popups v3 elements, StoriesView, StoriesWidget and the stories viewer carry their shop where it is known, and the popup lines are written whatever the level while PopupsV3.debug is on; core_flag_mismatch is logged once per shop, not again when a registered shop makes its instance; an unexpected failure of the new core's request is sdk_log, not callback_failed; a failed stories v3 event is logged once, as request_failed
…K.state (SdkState: notInitialized, initializing, ready, retrying, refused) with onStateChange listeners called on the main thread once per change, a throwing one logged as callback_failed; shopId, deviceId and sessionId, with getDid()/getSid() returning "" when there is none, also before initialization; Rees46Config.deviceId, a did the app brings, taken while the shop has none; a second Rees46.initialize for a shop returns its instance (a different config logs invalid_config, already_initialized) and calls from several threads make one; Rees46.register and Rees46.instance, with registerShops and getInstance kept as deprecated delegates; UnknownShopIdException and AmbiguousShopException share Rees46Error, still an IllegalStateException; release() stops the instance and unregisters it, later calls fail with notInitialized (onError(-1), a request waiting for a did included, deleteUserCredentials throws and deletes nothing), and a new initialize makes a fresh instance. The legacy core goes from initializing to ready once the did and session are in place, at once for a known device, and is never retrying or refused. The new core has its own /init: a shop with a did (stored, from the config or from the saved answer) is ready at once while /init goes in the background; no answer, a 2xx without a did, 5xx, 408, 410, 417, 426 and 429 are retrying with pauses of 1 s doubling to 5 min, spread by 20 %, or the Retry-After of a 429 or 503, and without a did and a network /init waits for the network; 402, 403, 404 and other 4xx refuse the shop, kept on disk until a later launch's /init succeeds, and every request then fails with shopBlocked (onError(402)); each successful answer is saved, its seance becomes the sid and a stale sid is not sent; a request waits for the instance within its read timeout; needReInitialization really gets a new did; /init carries the configured stream, tz with summer time and the advertising id only with Rees46Config.sendAdvertisingId; it goes again on returning to the foreground after two hours and through an internal checkShop() at most every 10 minutes; logs init_succeeded, init_retry, init_failed, init_refused, init_saved_answer and init_skipped
…ingId, read once a launch and never empty, and /init sends no cookie

An id of zeros or a blank one does not go; one that cannot be read is logged as
advertising_id_failed and /init goes without it. With the app's CookieHandler installed the
new core's requests carry no cookie, and the /init after deleteUserCredentials no did. An
/init that cannot be built logs request_build_failed and an answer cut short logs
decoding_failed; both are repeated as retrying.
…is no longer found under the shop it left

SDK.initialize on an object live for one shop with another shop stops the old start, but the
registry kept mapping the old shop to the object, so Rees46.instance of the old shop handed
out an instance of the new one. Registering the object for a shop now drops its other
mappings.

The tests pin the deprecated initialize on both cores: called again the same way it starts
the object once; with another stream it keeps the first config and logs invalid_config;
after release it starts over; after a start on the new core it runs on it with one
core_flag_mismatch. They also pin an object never initialized, the legacy request made as a
deletion begins (old did) and after the wipe (waits for the new did), the bridges' results of
the old callbacks and of the legacy queueEvent, and BridgeErrors.errorOf for each state.
…e did of init on both cores, a failing provider sends nothing, FCM's onNewToken reaches every live shop and an instance's own onToken wins over the facade's

PushTokenManager builds its sources from a factory a test can replace; the providers on the classpath stay the default.
…ked from its extras, sets the source and calls onClicked once, for a live shop and for one registered but not created; a push's own type and id track nothing there, as in 2.49.0
…as opened for the helper's shop, whole, with its dismissal carrying the same push; one without a code or a type, or drawn before the process chose its core, reports nothing; a broken dismissal, extra or FCM message is logged, never thrown
…monitor's listeners and given back with the last of them, and each change reaches every listener once, one that throws stopping no other
…e oldest push past a hundred, logs a parked repeat that throws and a main thread that refuses a callback, and a bridge joining while a token comes hears it exactly once
…eek on the new core and is read on the legacy one, and an answer that is a JSON array counts as sent
…torage_failed with its operation and leaves the data as it was, a cleared event the disk keeps is never sent again, and the 2.4x store's numbers, flags and sets migrate with their types
… kept-alive connection breaks after it went is a timeout the queue repeats with a pause, not an event the server gets twice

retryOnConnectionFailure is off on the core's client, as core/network.md says. With it on, a request on a
pooled connection that the server dropped once the request was in went again on a new connection: the event
reached the server twice. A failure before anything was sent stays network.

OkHttp no longer tries the other addresses of a host by itself either: after one fails, the next request
goes to the next address. The init fixtures' server is reached by its address, as localhost has two.
…as emptied and there is nothing to send

core/init.md and contract/root.md now agree: every method of a refused shop answers shopBlocked except flush(),
whose only error is notInitialized after release(). flush(listener) hears a success.
…the queue hear cancelled, not shopBlocked

core/queue.md, «Пределы»: a dropped event's callback gets the error of its reason, and refused is cancelled, as
overflow and delete_user_credentials are. The old onError gets -1 instead of 402. An event offered after the
refusal is still refused at once with shopBlocked. A test reads the whole error behind each reason's drop:
rejected and service_refused give the answer's http code, attempts the last one's, expired timeout, overflow
and delete_user_credentials cancelled.
…no longer extend the session; a tap still does, as the server counts it

core/session.md: /init and every tracking event move the session's last activity, and of the push events only
track/clicked, which the server also counts. A delivery that wakes an instance brought up for a push in the
background no longer keeps a session alive that would have ended, so the app's next start begins a new one as
the server does.
…when its session ended: it would start a session there, which the queue never does

The fallback that sends an event once as a request when the disk refused it follows the queue's rules
(«Запасная прямая отправка соблюдает те же правила»). A tracking event whose session's window ended, while
the app is in the background, would have asked /init for a new session from there. It is not accepted
now: nothing goes, its listener hears cancelled (onError -1) and request_failed is logged with not_ready. A
push event needs no session and still goes; so does a tracking event in the foreground.
…deleted customer's events on disk: the clear waits for the events accepted before it to be written

After release() the queue takes no command, and a clear ran at once, while the writer still wrote the events
accepted before the release. Those files outlived the deletion, and the next launch sent them with the next
customer's did. A clear of a released queue now waits for the writer to drain, then empties the queue. Tests
also pin an event a cancelling release overtakes: written for the next launch, its listener hears cancelled at
once, and the queue made next sends it.
… invalid_config, push_token_skipped says sent_recently, no_device_id, auto_send_off or push_only, and the codes are checked against logging.md itself

core/logging.md lists invalid_config with context.reason device_id_kept, not a code of its own: Rees46Config.deviceId
that a shop with a did of its own does not take is logged so. The reasons of push_token_skipped are the contract's,
and a token FCM or HMS gives a shop that does not send tokens by itself (autoSendPushToken = false) is now logged
as skipped with auto_send_off, on both cores, instead of nothing.

LogCodesTest read its codes from a copy of the table kept in the test, which had drifted. The contract's
logging.md is now copied beside the fixtures, as they are, and the test reads the table's rows, the area codes
named after it and the reasons of the rows from it.
…e did, so the token goes to the new did at once instead of up to a week later, on both cores

The week the token was sent belongs to the did that sent it. On the new core needReInitialization forgot the
did, the session and the saved /init answer but kept the dates the token was sent and the claims of the sends:
/init gave a new did, and the token was skipped as sent this week, so pushes could not reach the new profile.
The dates and the claims now go with the did, as after deleteUserCredentials.

The legacy core's /init for needReInitialization carries the stored did, and the server usually keeps it; the
week then stays right. When an answer hands out another did, the week is forgotten before the providers are
asked for their tokens, and the token goes to the new did.
…stance instead of being dropped as no_did

A shop registered but not created is brought up for a push; when the app's first call (Rees46.instance on the
main thread) made the shop's full instance before the push's instance had read its did from the disk, the
push's instance had been released: CoreInit.hasDid() answered no for a released instance whatever its config or
saved /init answer held, and the push was dropped as no_did although the full instance would take the did and
the queue's refusal would hand the event to it. A push-only instance that gave way no longer drops the push:
its queue refuses the event and it goes to the instance that took its place. hasDid() of an instance released
before it read the disk reads the sources its start would have taken.
… /push that goes while it is on its way to the shop's instance carries it; a tap no queue takes puts the source before it back

The source of a tap was set once a queue accepted the tap. A tap the push's instance refused, after it gave way,
was handed to the app's instance off the refusing thread, and a view the app tracked meanwhile could be sent
first, without the source: the first /push of the visit lost its attribution. The source is now set before the
tap is offered, and when no queue takes it (the instance released, the shop refused) the source it replaced,
if any, is put back, unless another tap or setSource changed it since.
…nds only /init and track/received, as 2.49.0 did; the push token and the profile go once the app takes the instance

A data push that starts the process for a shop registered without eagerInit and without a did made the shop's
full instance: besides the /init that gives the did the push's track/received waits for, the push's process read
the advertising id and sent profile/set, and fetched and sent the push token. 2.49.0 brought such a shop up
without the token and the profile. The instance is still the shop's full one, which the app then gets as it is;
it now starts without them, and when the app takes it (Rees46.instance, initialize, awaitInstance, SDK.instance)
the profile and the token go, once, each after the did.
…es gives the app its shop's full instance, and any initialize of the shop makes that instance give way

The app of the old API reaching SDK.instance after a push brought a lazily registered shop up got a new,
uninitialized SDK made current: notificationClicked on it threw UninitializedPropertyAccessException, and the
deprecated initialize on it registered a second instance of the shop beside the push's one, which kept its
start, its listeners and its queue. When the only live instance is a push-only one, SDK.instance now makes the
shop's full instance as Rees46.instance does. Whatever initializes a shop's instance — Rees46.initialize, the
deprecated initialize of another object — makes a push-only instance of the shop give way to it.
… a did fails with notInitialized when the instance gives way, instead of going without a did

An instance brought up for a push gives way to the app's without releasing its legacy core, so that the push's
tracking handed to it later still goes. Its requests still waiting for a did were then let go through that
live core with no did: the instance's /init had stopped and would never give one. They now fail at once with
notInitialized (onError -1), as on a released core, and nothing goes without a did.
… as the KDoc of Rees46Config and deleteUserCredentials now says

PopupsV3Api sends through the stories v3 client's HttpURLConnection, on either core.
…t had no test of their own

- On the legacy core an instance brought up for a push that gave way still sends the tracking its push hands
  it later, with its did (its core is not released).
- On the legacy core a shop whose did comes only from Rees46Config.deviceId, or only from the store of the
  releases before partitions, sends its push from a push-only instance without /init.
- A repeat of a push event that comes while the first is handed over is tried again when no queue takes the
  first, and the message goes when it comes again.
- deleteUserCredentials() while a token send is on its way: the send for the new did goes at once instead of
  waiting for the forgotten customer's, and the week is the new did's.
…hat may not go yet, the client's unexpected answers, a session that ends while the instance is not ready, files of another format, the queue made first, the exact limits, the five-minute cap, a lost network callback and hooks that throw

- A tracking event answered 404 again less than ten minutes after a check of the shop that told nothing waits
  until a check may go; neither flush, the foreground nor the network ends that wait, and nothing loops.
- A send that throws is held after a pause without counting an attempt; another error of the client drops the
  event as rejected; a cancel the queue did not make is repeated; a network lost on the way stops the pass
  without a pause or an attempt.
- A tracking event with a live session waits while the instance is not ready and goes with the next did; one
  whose window ends meanwhile goes with the session started after it.
- A file of another version, or without a path, a body or its time, is dropped as unreadable with decoding.
- A flush of the queue made first ends with the pass of the one that sends; released, that one hands sending back.
- An event exactly seven days old goes, exactly the cap of events stay, and one sent exactly ten seconds after it
  was made shows its popup.
- /init's pauses double to five minutes and stay there; a network that comes back without a callback is found
  within five minutes; hooks that throw are logged and change nothing.
…two deletions at once, the eager registration, listeners that throw, a popup held back, and the legacy core's repeated deliveries

- Two shops on the new core keep their own did, session and queue directory; one's Retry-After does not hold the
  other's events, one's refusal and deleted customer leave the other ready with its data, and calls of both from
  eight threads each get their own shop's answer.
- deleteUserCredentials() of a refused shop asks /init again: a success clears refused and takes events again,
  a refusal refuses again; flush then ends without an error.
- Two deleteUserCredentials() at once both end, on either core, with the server's did and no failure logged.
- register(eagerInit = true) makes each shop's instance with one /init on either core; awaitInstance of a shop
  registered but not created gets its full instance at once.
- A session listener, a flush listener and the bridges' push and token listeners that throw are logged, and the
  others still hear; a state listener hears notInitialized on release and nothing after.
- A shop initialized with the other core flag after a registration decided the process's core runs on that core,
  warned once.
- A popup the queue held back is not shown and is logged with why; the app hears the whole answer.
- On the legacy core every delivery of one message is sent, as 2.49.0 did.
…retry itself, which is logged after the state changes

The state reaches the listener before the repeat is logged, so a test that read the log as soon as it saw
retrying could find no init_retry yet on a busy machine. It now waits for the line on the log handler.
…not connect, and still never sends a request again once it went

Turning off retryOnConnectionFailure also stopped OkHttp from trying a host's next address after a connect
failure: on a network with broken IPv6 the first request failed after the connect timeout instead of going over
IPv4. It is on again, and what it would repeat is closed off instead:
- every POST body is one-shot: OkHttp 4.12 neither retries a request whose one-shot body started going out
  (RetryAndFollowUpInterceptor.recover) nor follows its answer up (408, 503);
- a request without a body (a GET, /init) would still be sent again on a new connection after one broke off:
  an attempt whose request went and got no answer marks the call, and a later attempt fails with a
  ProtocolException, which OkHttp never recovers from.
A connect failure happens before anything is sent, so it still moves on to the next route. A failure after
the request went stays timeout, one before it network. RetryAfterGuard is still needed: OkHttp follows up a
408 or a 503 with Retry-After 0 of a request without a body, and parses Retry-After as an Int for any 503,
which throws on a large number on its own thread. The init fixtures reach the server as localhost again.
@Xyzcancer
Xyzcancer merged commit 8aede7a into master Nov 16, 2026
1 check passed
@Xyzcancer
Xyzcancer deleted the feat/DEV-4724-core branch November 16, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant